package com.jlkf.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jlkf.service.SysUserService;
/**
 * 后台系统用户 登录
 * @author mq
 *
 */
@Controller
@RequestMapping("sysUser")
public class SysUserController {

	@Autowired
	private SysUserService sysUserService;
	
	//登录
		@RequestMapping("login")
		@ResponseBody
		public Object getLogin(@RequestBody String json,HttpSession session){
			return sysUserService.getLogin(json,session);
		}
		
		@RequestMapping("loginout")
		@ResponseBody
		 public void loginout(HttpServletRequest request,HttpServletResponse response) {
		    HttpSession session = request.getSession();
		    session.removeAttribute("user");
		    session.removeAttribute("srs");
		    //mode.setViewName("login");
		    try {
		      response.getWriter().write("<script>window.top.location.href=\"../login.jsp\";</script>");
		    } catch (Exception e) {
		      e.printStackTrace();
		    }
		  }
		//更新当前系统登录用户信息
		@RequestMapping("updateUser")
		@ResponseBody
		public Object updateUser(@RequestBody String json,HttpServletRequest request){
			return sysUserService.updateUser(json,request);
		}
		
		@RequestMapping("addOrUpdate")
		@ResponseBody
		public Object addOrUpdate(@RequestBody String json){
			return sysUserService.addOrUpdate(json);
		}
		
		@RequestMapping("getList")
		public Object getList(Integer pageNumber,Integer pageSize,String name,String account,Long roleId ){
			return sysUserService.getList(pageNumber,pageSize,name,account,roleId);
		}
		@RequestMapping("delete")
		public Object deleteRole(Long id){
			return sysUserService.deleteRole(id);
		}
		
}
